home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Path: shrike.irvine.com!adam
- From: adam@irvine.com (Adam Beneschan)
- Subject: Re: Avoiding typedefs (was: Hungarian notation)
- In-Reply-To: Douglas Evan Cook's message of Mon, 22 Jan 1996 14:58:59 -0700
- References: <30C40F77.53B5@swsbbs.com> <4bd <4cc2b2$11jq@navajo.gate.net>
- <4cud8f$gup@news.netvision.net.il> <4dttefINNo29@keats.ugrad.cs.ubc.ca> <Pine.HPP.3.91.960122145028.27524A-100000@clear.cs.byu.edu>
- Sender: usenet@irvine.com (News Administration)
- Organization: Irvine Compiler Corp., Irvine, California, USA
- Date: Tue, 23 Jan 1996 02:16:36 GMT
- Message-ID: <DLM3no.4M6@irvine.com>
-
- Douglas Evan Cook <cookd@cs.byu.edu> writes:
-
- > On 21 Jan 1996, Kazimir Kylheku wrote:
- >
- > > I say, don't bother. I avoid typedefs like the plague, even for structures. I
- > > much rather write the longer form.
- > >
- > > void myfunction(struct whatever *x);
- > >
- > > Using excessive typedefs will just occlude your code. What is the point of
- > > having a separate type for MSEC? Later, when someone sees a declaration of a
- > > variable of type MSEC, he will have to go hunting and pecking for the
- > > definition of MSEC. It _obviously_ stands for milliseconds, but what the hell
- > > is it?
-
- If MSEC obviously stands for milliseconds, then the answer to the
- question "what the heck is it" is "Milliseconds". If you care at that
- point how "milliseconds" is implemented, you need to go back and
- relearn about "abstraction" and why it's important.
-
- I'll grant that this isn't all that helpful in C, which doesn't
- contain a whole lot of support for abstract data types; so you pretty
- much *do* have to know what type of variable it is if you're going to
- use it. In C++ or Ada83 or Ada95 or UCSD Pascal or Modula or Eiffel,
- which do provide constructs allow you to define all the operations on
- a type in one place so you don't have to worry about it later, calling
- things by abstract type names without worrying about how they're
- implemented is an absolute MUST. (By the way, in response to an
- earlier post, THIS is the reason for having named types in those
- languages---NOT lazy compiler implementors.)
-
- > The way I was taught, you use typedefs only for variables that are likely
- > to change type (and you want to change all of the instances of that type
- > at once) and for cross-platform portability (in a multi-language
- > environment like Windows or when you are saving data to disk). Using it
- > for most other things will, as you said, only hamper coding and debugging
- > efforts. However, to use those examples to induce "typedefs are useless"
- > is jumping to a bad conclusion. If you want to argue that the uses that
- > I gave are bad, we can do that, but to generalize without looking at all
- > potential uses isn't a good idea.
-
- I must be missing something. How does
-
- void myfunction (Whatever *x);
-
- (where Whatever is a typedef) "occlude your code" or "hamper coding
- and debugging efforts", while
-
- void myfunction (struct whatever *x);
-
- doesn't? The second example looks just like the first, in that you're
- declaring a variable using some name that I'd have to go somewhere
- else and look up if I wanted to see how it was implemented. The only
- difference is a keyword.
-
- Or does the character sequence "struct" have some magical properties
- that cause occlusion to break up and everything to become clear?
-
- -- Adam
-